package com.wu.cloud.custom.configuration;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author xwu36
 */
@Configuration
public class RestTemplateConfiguration {

    static final Logger logger = LoggerFactory.getLogger(RestTemplateConfiguration.class);

    @Bean("pesk_template")
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        logger.info("RestTemplate init success");
        return new RestTemplate(factory);
    }

    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setReadTimeout(5000);
        factory.setConnectTimeout(5000);
        return factory;
    }

}
